package thread;

import java.util.concurrent.*;

public class ThreadDemo3 {
    public static void main(String[] args) {
        //创建线程任务资源对象
        MyCallable mc=new MyCallable();
        //创建线程任务对象,封装线程资源
        FutureTask<Integer> task=new FutureTask<>(mc);
        Thread t=new Thread(task);
        t.start();


    }
}
//编写一个类实现Callable接口
class MyCallable implements Callable<Integer>{
        @Override
        public Integer call() throws Exception{
            int sum=0;
            for(int i = 1;i<=100;i++){
                sum+=i;
                System.out.println("sum="+sum);
            }
            return sum;
        }

    }

